<style>
  .layui-btn {
    padding: 0 7px !important;
  }
  .layui-form-label{
    width: 100px !important;
  }
  .layui-laypage a, .layui-laypage span{
    background-color: #f2f2f2;
  }
</style>
<div style="margin-top: 1%;">
  <form class="layui-form" action="">

    <div class="layui-form-item ">
      <div class="layui-inline ">
        <label class="layui-form-label">上线时间:</label>
        <div class="layui-input-inline">
          <input type="text" id="startTimeval" lay-verify="date" autocomplete="off" class="layui-input">
        </div>
      </div>

      <!--<div class="layui-form-item layui-col-xs12">-->
      <div class="layui-inline">
        <label class="layui-form-label">下线时间:</label>
        <div class="layui-input-inline">
          <input type="text" id="endTimeval" lay-verify="date"  autocomplete="off" class="layui-input">
        </div>
      </div>
      <!--</div>-->


      <div class="layui-inline">
        <button type="button" class="layui-btn" id="btnSearch">搜索</button>
      </div>
    </div>
  </form>
</div>

<div style="padding-left: 50px;">
  <caption style="margin-left: 40px;"><span >
                <button type="button" class="btn btn-primary layui-btn"  onclick="method5('tableExcel')">
                    <span class="glyphicon glyphicon-folder-open">导出Excel</span>
                </button>
            </span>
  </caption>
</div>
<script type="text/html" id="tol">
  <div>
    <div style="float:left;">密钥充值记录</div>
    <div style="float:right;margin-right: 50px">共有数据：<span id="zong"></span>条</div>
  </div>

</script>

<table class="layui-table" id="Keyrechargedata" lay-filter="Keyrechargedata"></table>
<div id="demo7" style="text-align: center"></div>

<!--导出表格-->
<script>

  var local_store = layui.data("local_store");
  var local = local_store.token;
  $.ajax({
    type:"get",
    url:"/admin/station/query/stationLoginQuanxXian?stationId="+json.id,
    dataType: "json",
    contentType:"application/json;charset=utf-8",
    beforeSend: function(request) {
      request.setRequestHeader("token", local);
    },
    success:function (res) {
      if(res.code==500){
        alert("权限不足")
        location="../../admin/main.html";
        return
      }}})
  //导出表格
  var idTmr;
  function  getExplorer() {
    var explorer = window.navigator.userAgent ;
    //ie
    if (explorer.indexOf("MSIE") >= 0) {
      return 'ie';
    }
    //firefox
    else if (explorer.indexOf("Firefox") >= 0) {
      return 'Firefox';
    }
    //Chrome
    else if(explorer.indexOf("Chrome") >= 0){
      return 'Chrome';
    }
    //Opera
    else if(explorer.indexOf("Opera") >= 0){
      return 'Opera';
    }
    //Safari
    else if(explorer.indexOf("Safari") >= 0){
      return 'Safari';
    }
  }
  function method5(tableid) {
    if(getExplorer()=='ie')
    {
      var curTbl = document.getElementById(tableid);
      var oXL = new ActiveXObject("Excel.Application");
      var oWB = oXL.Workbooks.Add();
      var xlsheet = oWB.Worksheets(1);
      var sel = document.body.createTextRange();
      sel.moveToElementText(curTbl);
      sel.select();
      sel.execCommand("Copy");
      xlsheet.Paste();
      oXL.Visible = true;

      try {
        var fname = oXL.Application.GetSaveAsFilename("Excel.xls", "Excel Spreadsheets (*.xls), *.xls");
      } catch (e) {
        print("Nested catch caught " + e);
      } finally {
        oWB.SaveAs(fname);
        oWB.Close(savechanges = false);
        oXL.Quit();
        oXL = null;
        idTmr = window.setInterval("Cleanup();", 1);
      }

    }
    else
    {
      tableToExcel(tableid)
    }
  }
  function Cleanup() {
    window.clearInterval(idTmr);
    CollectGarbage();
  }
  var tableToExcel = (function() {
    var uri = 'data:application/vnd.ms-excel;base64,',
            template = '<html><head><meta charset="UTF-8"></head><body><table>{table}</table></body></html>',
            base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) },
            format = function(s, c) {
              return s.replace(/{(\w+)}/g,
                      function(m, p) { return c[p]; }) }
    return function(table, name) {
      if (!table.nodeType) table = document.getElementById(table)
      var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
      window.location.href = uri + base64(format(template, ctx))
    }
  })()
</script>

<!--表格数据-->
<script>


  var pages= localStorage.getItem('page');
  function GetRequest() {
    var url = decodeURI(location.search); //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
      var str = url.substr(1);
      strs = str.split("&");
      for(var i = 0; i < strs.length; i ++) {
        theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
      }
    }
    return theRequest;
  }
  var json=GetRequest();
  layui.use(['table','util', 'layer'], function () {
    var table = layui.table;
    var layer = layui.layer;
    var util = layui.util;

    table.render({
      elem: '#Keyrechargedata'
      , id: "t"
      , toolbar: "#tol"
      , method: 'get'
      , url: '/admin/station-key-recharge/queryKeyRecharge?stationId=' + json.id
      , cols: [[
        // {checkbox: true, fixed: true}
         {
          field: 'station_key_recharge_id', title: 'ID', width: "24%",
          align: "center"
        }
        ,
        {
          field: 'station_key_recharge_time', title: '充值时间',
          templet: "<div> {{  Format(d.station_key_recharge_time,'yyyy-MM-dd hh:mm:ss')}}</div>",
          // width: "25%",
          align: "center"
        }
        , {
          field: 'station_key_recharge_sum',
          // width: "24%",
          align: "center", title: '充值数量'
        }
        , {
          field: 'admin_name',
          // width: "24%",
          align: "center", title: '处理人'
        }
      ]],page:{
        curr:pages
      },
      done: function (res, curr, count1) {
        localStorage.setItem('page',curr);
        $("#zong").html(count1);
      }
    });

    $("#btnSearch").click(function(){
      table.reload("t",{
        where:{
          startTime:$("#startTimeval").val(),
          endTime:$("#endTimeval").val()
        },
        page:{
          curr:1
        }
      });
    });

  });
  layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

    //日期
    laydate.render({
      elem: '#startTimeval'
      ,type: 'datetime'
    });
    laydate.render({
      elem: '#endTimeval'
      ,type: 'datetime'
    });
  });
</script>

<!--table日期转换格式-->
<script>
  function Format(datetime,fmt) {
    if (parseInt(datetime)==datetime) {
      if (datetime.length==10) {
        datetime=parseInt(datetime)*1000;
      } else if(datetime.length==13) {
        datetime=parseInt(datetime);
      }
    }
    datetime=new Date(datetime);
    var o = {
      "M+" : datetime.getMonth()+1,                 //月份
      "d+" : datetime.getDate(),                    //日
      "h+" : datetime.getHours(),                   //小时
      "m+" : datetime.getMinutes(),                 //分
      "s+" : datetime.getSeconds(),                 //秒
      "q+" : Math.floor((datetime.getMonth()+3)/3), //季度
      "S"  : datetime.getMilliseconds()             //毫秒
    };
    if(/(y+)/.test(fmt))
      fmt=fmt.replace(RegExp.$1, (datetime.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
      if(new RegExp("("+ k +")").test(fmt))
        fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
    return fmt;
  }
</script>


